package wails_utils

import (
	"golang.org/x/sys/windows/registry"
)

const (
	keyPath = `SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
)

// SetRegisterRegedit 修改注册表信息
func SetRegisterRegedit(valueName, value string) error {
	// 打开注册表键
	key, err := registry.OpenKey(registry.CURRENT_USER, keyPath, registry.ALL_ACCESS)
	if err != nil {
		return err
	}
	defer key.Close()

	// 设置注册表值
	err = key.SetStringValue(valueName, value)
	if err != nil {
		return err
	}
	return nil
}

// GetRegisterRegedit 根据注册表，查找注册信息
func GetRegisterRegedit(valueName string) (string, error) {
	key, err := registry.OpenKey(
		registry.CURRENT_USER,
		keyPath,
		registry.QUERY_VALUE)

	if err != nil {
		return "", err
	}
	regRes, _, err := key.GetStringValue(valueName)
	if err == nil {
		return regRes, nil
	}
	return "", nil
}
